/******************************************************************************************************
Copyright (C) 2012 Mestrelab Research S.L. All rights reserved.

This file is part of the MNova scripting toolkit.

Authorized users of MNova Software may use this file freely, but this file is provided AS IS
with NO WARRANTY OF ANY KIND, INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE.
*****************************************************************************************************/
/** Script Ui Example
 * If Mnova finds a valid *.mui file in the scripts directories (e.g. scriptCustom.mui) a script object with the same basename (scriptCustom) will be created automatically and added as a property to the global object MnUi (MnUi.scriptCustom)
 * To run each one of the actions defined in the mui file, Mnova will try to run a function inside the custom ui object with the same name as the action. (MnUi.scriptCustom.actionName)
 * Moreover, Mnova will use two default functions(if they exist): 
 * init() to be called when Mnova starts after loading the default scripts (MnUi.scriptCustom.init())
 * update(aUpdateObj) to be called everytime the UI needs and update (MnUi.scriptCustom.update(aUpdateObj)). The aUpdateObj properties are called in the same way as the actions in the mui file having as properties standard UI properties (enabled, checked, text, tooltip, visible...), modifying them will modify the UI.
 * All the above functions will be called with the same this object so it's possible to set an internal state to the MnUi.scriptCustom object.
 */
 
 //! Init function, we add our custom variables.
MnUi.scriptCustom.init = function()
{
	print("Init scriptCustom")
	this.fEnabled1 = true
	this.fEnabled2 = true
}

//! Update function. aUpdateActionObj has as properties the actions defined in the mui file.
MnUi.scriptCustom.update = function(aUpdateObj)
{
	print("Update actions")
	print(this.fEnabled1+" "+this.fEnabled2)
	aUpdateObj.scriptCustomAction.enabled = this.fEnabled1
	if(aUpdateObj.scriptCustomAction.enabled)
		aUpdateObj.scriptCustomAction.text = "Show a Dialog..."
	else
		aUpdateObj.scriptCustomAction.text = "Disabled"
	aUpdateObj.scriptCustomAction2.checked = this.fEnabled1
	aUpdateObj.scriptCustomAction2.enabled = this.fEnabled2
	aUpdateObj.scriptCustomAction3.checked = this.fEnabled2
}

//! This function will be called when the mui file action "scriptCustomAction" is triggered
MnUi.scriptCustom.scriptCustomAction = function()
{
	print("scriptCustomAction2")
	MessageBox.information("You Pressed the Button", MessageBox.Ok)
}

//! The internal state of the this object can be modified as a result of one action
MnUi.scriptCustom.scriptCustomAction2 = function()
{
	print("scriptCustomAction2")
	this.fEnabled1 = !this.fEnabled1
	var message = ""
	if(this.fEnabled1)
		message = "Action 1 Enabled"
	else
		message = "Action 1 Disabled"
	MessageBox.information(message, MessageBox.Ok)
}

MnUi.scriptCustom.scriptCustomAction3 = function()
{
	print("scriptCustomAction3")
	this.fEnabled2 = !this.fEnabled2
	var message = ""
	if(this.fEnabled2)
		message = "Action 2 Enabled"
	else
		message = "Action 2 Disabled"
	MessageBox.information(message, MessageBox.Ok)
}
